package com.example.cms;

import java.io.IOException;
import java.util.List;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;


import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


public class VistaEditWayPoints extends MapActivity {



	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	public void modificawp() {
    	EditText et = (EditText) this.findViewById(R.id.editTextModificarWP0);
    	int numfila = VistaSelecTrajecte.ruta_sel;
    	String s;
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][10]);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][10] = s;
    	else VistaSelecTrajecte.RUTES[numfila][10] = "Unspecified";
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP1);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][11] = s;
    	else VistaSelecTrajecte.RUTES[numfila][11] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][11]);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP2);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][12] = s;
    	else VistaSelecTrajecte.RUTES[numfila][12] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][12]);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP3);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][13] = s;
    	else VistaSelecTrajecte.RUTES[numfila][13] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][13]);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP4);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][14] = s;
    	else VistaSelecTrajecte.RUTES[numfila][14] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][14]);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP5);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][15] = s;
    	else VistaSelecTrajecte.RUTES[numfila][15] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][15]);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP6);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][16] = s;
    	else VistaSelecTrajecte.RUTES[numfila][16] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][16]);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP7);
    	s = et.getText().toString();
    	if (!s.equals("")) VistaSelecTrajecte.RUTES[numfila][17] = s;
    	else VistaSelecTrajecte.RUTES[numfila][17] = "Unspecified";
    	//et.setText(VistaSelecTrajecte.RUTES[numfila][17]);
	}
	public void carregaWP() {
    	EditText et = (EditText) this.findViewById(R.id.editTextModificarWP0);
    	int numfila = VistaSelecTrajecte.ruta_sel;
    	String punt = VistaSelecTrajecte.RUTES[numfila][10];
    	if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP1);
    	punt = VistaSelecTrajecte.RUTES[numfila][11];
    	if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP2);
    	 punt = VistaSelecTrajecte.RUTES[numfila][12];
    	 if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP3);
    	 punt = VistaSelecTrajecte.RUTES[numfila][13];
    	 if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP4);
    	 punt = VistaSelecTrajecte.RUTES[numfila][14];
    	 if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP5);
    	 punt = VistaSelecTrajecte.RUTES[numfila][15];
    	 if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP6);
    	 punt = VistaSelecTrajecte.RUTES[numfila][16];
    	 if (!punt.equals("Unspecified")) et.setText(punt);
    	
    	et = (EditText) this.findViewById(R.id.editTextModificarWP7);
    	 punt = VistaSelecTrajecte.RUTES[numfila][17];
    	 if (!punt.equals("Unspecified")) et.setText(punt);
	}
	
	 /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.modificarwaypoints);
        System.out.println("EditWayP ruta sel = " + VistaSelecTrajecte.ruta_sel);
        Button tornar = (Button) this.findViewById(R.id.buttonModificarWPTornar);
    	tornar.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				finish();
				
			}
  			
  		});
        Button OK = (Button) this.findViewById(R.id.buttonModificarWPOK);
    	OK.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
		        modificawp();
				finish();
				
			}
  			
  		});
    	carregaWP();
    }
}
